package com.cencat.common.enums;

/**
 * 审核状态枚举
 * 
 * @author cencat
 * @since 2024-01-01
 */
public enum AuditStatus {

    /**
     * 待审核
     */
    PENDING("PENDING", "待审核"),

    /**
     * 审核通过
     */
    APPROVED("APPROVED", "审核通过"),

    /**
     * 审核拒绝
     */
    REJECTED("REJECTED", "审核拒绝"),

    /**
     * 审核中
     */
    REVIEWING("REVIEWING", "审核中"),

    /**
     * 需要补充材料
     */
    NEED_SUPPLEMENT("NEED_SUPPLEMENT", "需要补充材料"),

    /**
     * 已撤回
     */
    WITHDRAWN("WITHDRAWN", "已撤回");

    /**
     * 状态码
     */
    private final String code;

    /**
     * 状态描述
     */
    private final String description;

    /**
     * 构造函数
     * 
     * @param code 状态码
     * @param description 状态描述
     */
    AuditStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 获取状态码
     * 
     * @return 状态码
     */
    public String getCode() {
        return code;
    }

    /**
     * 获取状态描述
     * 
     * @return 状态描述
     */
    public String getDescription() {
        return description;
    }

    /**
     * 根据状态码获取枚举
     * 
     * @param code 状态码
     * @return 审核状态枚举
     */
    public static AuditStatus getByCode(String code) {
        if (code == null) {
            return null;
        }
        for (AuditStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    /**
     * 是否为待审核状态
     * 
     * @return 是否为待审核状态
     */
    public boolean isPending() {
        return this == PENDING;
    }

    /**
     * 是否为审核通过状态
     * 
     * @return 是否为审核通过状态
     */
    public boolean isApproved() {
        return this == APPROVED;
    }

    /**
     * 是否为审核拒绝状态
     * 
     * @return 是否为审核拒绝状态
     */
    public boolean isRejected() {
        return this == REJECTED;
    }

    /**
     * 是否可以修改
     * 
     * @return 是否可以修改
     */
    public boolean canModify() {
        return this == PENDING || this == NEED_SUPPLEMENT || this == WITHDRAWN;
    }

    /**
     * 是否为最终状态
     * 
     * @return 是否为最终状态
     */
    public boolean isFinalStatus() {
        return this == APPROVED || this == REJECTED;
    }

    /**
     * 获取下一个可能的状态
     * 
     * @return 下一个可能的状态列表
     */
    public AuditStatus[] getNextPossibleStatuses() {
        switch (this) {
            case PENDING:
                return new AuditStatus[]{REVIEWING, APPROVED, REJECTED, NEED_SUPPLEMENT};
            case REVIEWING:
                return new AuditStatus[]{APPROVED, REJECTED, NEED_SUPPLEMENT};
            case NEED_SUPPLEMENT:
                return new AuditStatus[]{PENDING, WITHDRAWN};
            case WITHDRAWN:
                return new AuditStatus[]{PENDING};
            default:
                return new AuditStatus[]{};
        }
    }
}